//
//  GroupDetailUserCell.m
//  SportSocial
//
//  Created by yull on 15/1/28.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "GroupDetailUserCell.h"
#import <UIImageView+WebCache.h>

@implementation GroupDetailUserCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor clearColor];
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.userArray = [NSMutableArray array];
        
        CGFloat orginx = 10;
        CGFloat width = 54;
        for (NSInteger i=0;i<4;i++) {
            CGRect rect = CGRectMake(orginx + i * 65, 10, width, width);
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:rect];
            imageView.layer.cornerRadius = width/2;
            imageView.layer.masksToBounds = YES;
            imageView.backgroundColor = [UIColor clearColor];
            [self.contentView addSubview:imageView];
            [self.userArray addObject:imageView];
        }
        
        CGRect rect = CGRectMake(0, 0, self.contentView.width + 5, self.contentView.height);
        self.countLabel = [[UILabel alloc] initWithFrame:rect];
        self.countLabel.backgroundColor = [UIColor clearColor];
        self.countLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        self.countLabel.textAlignment = NSTextAlignmentRight;
        self.countLabel.textColor = RGB(90, 90, 90);
        self.countLabel.font = [UIFont systemFontOfSize:14.0f];
        [self.contentView addSubview:self.countLabel];
    }
    return self;
}

+ (CGFloat)groupDetailUserCellHeight
{
    return 76.0f;
}

- (void)drawCellWithArray:(NSArray *)array
{
    for (NSInteger i=0;i<self.userArray.count;i++) {
        UIImageView *imageView = [self.userArray objectAtIndex:i];
        if (i < array.count) {
            UserModel *userModel = [array objectAtIndex:i];
            [imageView sd_setImageWithURL:[NSURL URLWithString:userModel.icon] placeholderImage:[UIImage imageNamed:@"zc_photo_bg"]];
        }else {
            self.imageView.image = nil;
        }
    }
    
    self.countLabel.text = [[NSString alloc] initWithFormat:@"%lu人",(unsigned long)array.count];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (UIEdgeInsets)layoutMargins
{
    return UIEdgeInsetsMake(0, 10, 0, 0);
}

@end
